package tp.pr4.instructions;

import tp.pr4.Message;
import tp.pr4.NavigationModule;
import tp.pr4.RobotEngine;
import tp.pr4.instructions.exceptions.InstructionExecutionException;
import tp.pr4.instructions.exceptions.WrongInstructionFormatException;
import tp.pr4.items.ItemContainer;

public class RadarInstruction implements Instruction {

	@Override
	public Instruction parse(String cad) throws WrongInstructionFormatException {
		String[] words = cad.split(" ");
		for (String i : Message.RADAR_INSTRUCTION) {
			if (words[0].equalsIgnoreCase(i))
				return new RadarInstruction();
		}
		throw new WrongInstructionFormatException(Message.NOT_UNDERSTAND);
	}

	@Override
	public String getHelp() {
		String help = Message.RADAR_INSTRUCTION[0];
		for (int i = 1; i < Message.RADAR_INSTRUCTION.length; i++)
			help += "|" + Message.RADAR_INSTRUCTION[i];

		return help;
	}

	@Override
	public void configureContext(RobotEngine engine,
			NavigationModule navigation, ItemContainer robotContainer) {
		this.navigation = navigation;
	}

	@Override
	public void execute() throws InstructionExecutionException {
		navigation.scanCurrentPlace();
	}
	
	NavigationModule navigation;
}
